package gc3d.griddata;

/**
 * @author Pierrick
 * Temp class if we choose to avoid FTP
 * each node give back the PNG
 * then the TaskSplit reducer put then together in an array
 * then we just have to write them in System.getProperty("java.io.tmpdir")
 * ISSUE: see if the Java-heap-size is enough for this system
 */
public class ArrayPNG {
	private static int ONE_FRAME  = -1;
	private static int ALL_FRAMES = -2;
	private int frame;
	private int numberOfFrames;
	private SimpleFile []pngs;

	public ArrayPNG(int numberOfFrames) {
		this.frame = ArrayPNG.ALL_FRAMES;
		this.numberOfFrames = numberOfFrames;
		this.pngs = new SimpleFile[numberOfFrames+1];
	}

	public ArrayPNG(int frame, SimpleFile png) {
		this.frame = frame;
		this.numberOfFrames = ArrayPNG.ONE_FRAME;
		this.pngs = new SimpleFile[1];
		this.pngs[0] = png;
	}

	public void setPNG(int frame, SimpleFile png) {
		if (frame <= numberOfFrames && frame >= 0) {
			this.pngs[frame] = png;
		} //else throw OutOfRange
	}

	// called by TaskSplit reducer
	public void add(ArrayPNG a) {
		this.pngs[a.frame] = a.pngs[0];
	}
}
